add_executable(kernel)
file(GLOB sources *.c)
target_sources(kernel PUBLIC ${sources})

target_link_libraries(kernel PRIVATE kernel_dependencies)
#target_link_libraries(kernel PRIVATE device)

target_include_directories(kernel PRIVATE ${PROJECT_SOURCE_DIR}/include)
#target_include_directories(kernel PRIVATE ${PROJECT_SOURCE_DIR}/include/device)

target_compile_options(kernel PUBLIC -m32)
# dont use gnu build-in function
target_compile_options(kernel PUBLIC -fno-builtin)

target_link_options(kernel PRIVATE -m elf_i386)
target_link_options(kernel PRIVATE -e main)
target_link_options(kernel PRIVATE -Ttext 0xc0001500)

# place main fuction to the start of .text section
file(GLOB LINKER_SCRIPT_CONTENT ${CMAKE_CURRENT_SOURCE_DIR}/main.ld)
target_link_options(kernel PRIVATE "--script=${LINKER_SCRIPT_CONTENT}")

set_target_properties(kernel 
  PROPERTIES
  SUFFIX .bin)

add_custom_command(
  TARGET kernel
  POST_BUILD
  COMMAND dd if=${EXECUTABLE_OUTPUT_PATH}/kernel.bin of=${PROJECT_SOURCE_DIR}/hd60M.img bs=512 count=200 seek=9 conv=notrunc
  COMMENT "write kernel to hard desk"
  VERBATIM
  )
